//
//  MainMenuScene.m
//  z_boxem
//
//  Created by A B on 2/4/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MainMenuScene.h"
#import "HelloWorldLayer.h"
#import "ScoresScene.h"
#import "SelectLevelScene.h"

@implementation MainMenuScene

+(id) scene
{
    return [MainMenuScene sceneWith:NO];
}

+(id) sceneWith:(BOOL)pause
{
    CCScene *scene = [CCScene node];
    
    MainMenuScene *layer = [[MainMenuScene alloc] initWithPause:pause];
    
    [scene addChild: layer];
    
    return scene;
}



-(id) initWithPause: (BOOL) pause
{
    
    if( (self=[super init] )) {
        
        
        CCSprite *background = [CCSprite spriteWithFile:@"background2.jpg"];
        background.scaleX = 0.55f;
        background.scaleY = 0.55f;
        background.position = ccp(240, 160);
        background.anchorPoint=ccp(0.5f, 0.5f);
        [self addChild:background];
        
        CCLabelTTF *title = [CCLabelTTF labelWithString:@"Main Menu" fontName:@"Courier" fontSize:64];
        title.position =  ccp(240, 280);
        title.color = ccBLACK;
        
        [self addChild: title];
        
        CCLayer *menuLayer = [[CCLayer alloc] init];
        [self addChild:menuLayer];
        
        CCMenu *menu = [CCMenu menuWithItems: nil];
        
        if(pause == NO){
            CCMenuItem *startButton = [CCMenuItemFont
                                       itemFromString:@"Start"
                                       target:self
                                       selector:@selector(startGame:)];
        
            
            [menu addChild: startButton];
        }
        else{
                CCMenuItem *resumeItem = [CCMenuItemFont itemFromString:@"Resume" target:self selector:@selector(resumeGame:)];   
                [menu addChild: resumeItem];
            

        }
        CCMenuItem *scoresItem = [CCMenuItemFont itemFromString:@"Scores" target:self selector:@selector(showScores:)];  
        [menu addChild: scoresItem];
             
        CCMenuItem *selectLevelItem = [CCMenuItemFont itemFromString:@"Select level" target:self selector:@selector(selectLevel:)];
        [menu addChild: selectLevelItem];
        
        [menu alignItemsVertically];
        [menuLayer addChild: menu];
        
        
    }
    return self;
}

- (void) selectLevel: (id) sender
{
    [[CCDirector sharedDirector] replaceScene:[SelectLevelScene scene]];
}


- (void) startGame: (id) sender
{
    [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer sceneWith:1]];
}
- (void) showScores: (id) sender
{
    [[CCDirector sharedDirector] replaceScene:[ScoresScene scene]];
}

-(void) resumeGame: (id) sender{
    [[CCDirector sharedDirector] popScene];
}
- (void) dealloc
{
    
    [super dealloc];
}

@end
